package com.example.administrator.myproject.user

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.View
import android.widget.EditText
import android.widget.TextView
import android.widget.Toast

import com.example.administrator.myproject.R
import com.example.administrator.myproject.home.AddCart
import com.example.administrator.myproject.utils.SPUtils

import cn.bmob.v3.exception.BmobException
import cn.bmob.v3.listener.SaveListener

/**
 * 评价
 */
class Assess : AppCompatActivity() {
    private var editText: EditText? = null
    private var textView: TextView? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.assess)
        editText = findViewById(R.id.commimt)
        textView = findViewById(R.id.commimt_btn)
        textView!!.setOnClickListener {
            val string = editText!!.text.toString()
            val addCart = AddCart()
            val name = SPUtils[this@Assess, "name", ""] as String?
            addCart.name = name
            addCart.type = string
            addCart.save(object : SaveListener<String>() {
                override fun done(s: String, e: BmobException?) {
                    if (e == null) {
                        Toast.makeText(this@Assess, "评价成功", Toast.LENGTH_SHORT).show()
                        finish()
                    } else {
                        Toast.makeText(this@Assess, "评价失败", Toast.LENGTH_SHORT).show()
                    }
                }
            })
        }
    }
}
